<?php
require_once("../../../config.inc.php");
require_once("../../../app/_inc/include.php");

$errMsg = "";
$entity = "";

$sWhere = '';
if (sxREQUEST('pagifilt')!='') {
	$sWhere = " WHERE domain LIKE '%".sxRAS('pagifilt')."%' OR description LIKE '%".sxRAS('pagifilt')."%' ";	
}
$link = 'domainList.php?xsn='.XSN;
$sSQL = "SELECT count(*) AS nr FROM domain $sWhere ";
$query = $objSDAO->query($sSQL,'numrec');
$rowNR = $objSDAO->fetch('numrec');
$startOffset = $endOffset = 0;
$sPaginaz = sxGetPaginaz($link, $rowNR['nr'], $startOffset, $endOffset);
$sFilter = sxGetFilter($link);

$sSQL = "SELECT * FROM domain $sWhere ORDER BY domain";
$query = $objSDAO->query($sSQL,'dom');
//output HTML
$aOpz = array("kMenu"=>'dam.dom');
echo(headerHTML($aOpz));
echo(bodyHTML($aOpz));
//output comandi
$aCmd = array(
						"are"=>array("pag"=>"../area/dataAreaList.php",
										"title"=>_t("List of Data-Areas"),
										"text"=>_t("data-area"),
										"perm"=>"upddom", "align"=>"L"),
						"ins"=>array("pag"=>"domainIns.php",
										"title"=>_t("add new domain"),
										"text"=>_t("new domain"),
										"perm"=>"upddom"),
						"back"=>array("pag"=>$objUser->getHistory(-1,false),
										"title"=>$objUser->getHistoryText(-1),
										"text"=>$objUser->getHistoryText(-1)
										)
					);
$sComandi = commandsHTML($aCmd);
echo $sFilter;	
echo $sComandi;	
echo $sPaginaz;	
//output dei dati
if($errMsg == ""){
	$numElem = 0;
	echo("<table class=\"tabl01\" width=\"100%\" cellpadding=\"3\" cellspacing=\"2\">\n");
	echo("<tr>" .
			"<td class=\"titl01\"colspan=\"6\">"._t("List of domains")."</td>" .
		"</tr>\n");
	
	echo("<tr>" .
			"<td class=\"tabh01\" width=\"1%\">"._t("f")."</td>" .
			"<td class=\"tabh01\" width=\"10%\">"._t("Domain")."</td>" .
			"<td class=\"tabh01\" width=\"30%\">"._t("Description")."</td>" .
			"<td class=\"tabh01\" width=\"20%\">"._t("Type")."</td>" .
			"<td class=\"tabh01\" width=\"39%\">"._t("Look-up")."</td>" .
		"</tr>\n");
	$currOffset = $startOffset;
	while($row = $objSDAO->fetch('dom',$startOffset)){
		$startOffset = '';
		$numElem ++;
		switch ($row["type"]) {
			case 'integer' :
			case 'date' :
			case 'date-time' :
			case 'text' :
			case 'long-text' :
			case 'blob' :
			case 'boolean' :
			 	$tipo = $row["type"];
				break;
			case 'string' :
			case 'variable-string' :
			 	$tipo = $row["type"]."(".$row["length"].")";
				break;
			default :
				$tipo = $row["type"]."(".$row["length"].",".$row["decimals"].")";
		}
		if ($row["enumerable"] == 'Y') {
			$lookUp = _t("domain values");
		} elseif ($row["lookup_entity"] != '') {
			$lookUp = $row["lookup_entity"].".".$row["lookup_attribute"];
		} else {	
			$lookUp = "&nbsp;";
		}
		echo("<tr>" .
				"<td class=\"text01\">".(($row["frequent"]=='Y')?'*':'&nbsp;')."</td>" .
				"<td class=\"text01\"><a class=\"text01\" ".goToPag("domainView.php?dom=".$row["domain"]."&xsn=".XSN).">".$row["domain"]."</a></td>" .
				"<td class=\"text01\">".sxHE($row["description"])."</td>" .
				"<td class=\"text01\">".$tipo."</td>" .
				"<td class=\"text01\">".$lookUp."</td>" .
			"</tr>\n");
		$currOffset++;
		if ($currOffset >= $endOffset) {break;}
	}
	if($numElem == 0)
		echo("<tr>" .
				"<td class=\"text01\" colspan=\"6\">"._t("no domain defined")."</td>".
			"</tr>\n");
	echo("</table>\n");
}else{
	echo($errMsg);
}
echo $sPaginaz;	
echo $sComandi;	
echo(footerHTML());
